package com.dalei.vds;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import android.app.ListActivity;
import android.content.ComponentName;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ListView;
import android.widget.SimpleAdapter;

public class SettingsActivity extends ListActivity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);

		List<Map<String, Object>> data = new ArrayList<Map<String, Object>>();

		// Add WiFi settings item
		Map<String, Object> wifi = new HashMap<String, Object>();
		wifi.put("icon", R.drawable.wifi);
		wifi.put("title", getString(R.string.wifi_settings));
		wifi.put("description", getString(R.string.wifi_settings_description));
		data.add(wifi);

		// Add server settings item
		Map<String, Object> server = new HashMap<String, Object>();
		server.put("icon", R.drawable.server);
		server.put("title", getString(R.string.server_settings));
		server.put("description",
				getString(R.string.server_settings_description));
		data.add(server);

		// Add time settings item
		Map<String, Object> time = new HashMap<String, Object>();
		time.put("icon", R.drawable.clock);
		time.put("title", getString(R.string.time_settings));
		time.put("description", getString(R.string.time_settings_description));
		data.add(time);

		// Add time settings item
		Map<String, Object> registerDevice = new HashMap<String, Object>();
		registerDevice.put("icon", R.drawable.phone);
		registerDevice.put("title", getString(R.string.device_registration));
		registerDevice.put("description",
				getString(R.string.device_registration_description));
		data.add(registerDevice);

		// Add images settings item
		Map<String, Object> image = new HashMap<String, Object>();
		image.put("icon", R.drawable.photo);
		image.put("title", getString(R.string.photo_settings));
		image.put("description", getString(R.string.photo_settings_description));
		data.add(image);

		// Bind an adapter to the list
		setListAdapter(new SimpleAdapter(this, data, R.layout.list_settings,
				new String[] { "icon", "title", "description" }, new int[] {
						R.id.list_settings_icon, R.id.list_settings_title,
						R.id.list_settings_description }));
	}

	@Override
	protected void onListItemClick(ListView l, View v, int position, long id) {
		// TODO Auto-generated method stub
		// super.onListItemClick(l, v, position, id);
		Intent intent = null;
		switch (position) {
		case 0:
			intent = new Intent();
			ComponentName component = new ComponentName("com.android.settings",
					"com.android.settings.wifi.WifiSettings");
			intent.setComponent(component);
			intent.setAction("android.settings.VIEW");
			startActivity(intent);
			break;

		case 1:
			intent = new Intent();
			intent.setClass(this, ServerSettingsActivity.class);
			startActivity(intent);
			break;

		case 2:
			intent = new Intent();
			intent.setClass(this, TimeSettingsActivity.class);
			startActivity(intent);
			break;

		case 3:
			intent = new Intent();
			intent.setClass(this, RegisterDeviceActivity.class);
			startActivity(intent);
			break;
			
		case 4:
			intent = new Intent();
			intent.setClass(this, ImageSettingsActivity.class);
			startActivity(intent);
			break;

		default:
			break;
		}
	}
}